package com.bw.shopping.bind;

import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.databinding.BindingAdapter;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bw.mvvm_common.BaseApplication;
import com.bw.mvvm_common.filed.UIField;
import com.bw.mvvm_common.network.load.LoadImage;
import com.bw.mvvm_common.utils.IntentAction;
import com.bw.shopping.R;
import com.bw.shopping.entity.ShoppingEnttiy;
import com.bw.shopping.mvvm.view.AdressActivity;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;

import org.greenrobot.eventbus.Subscribe;
import org.jetbrains.annotations.NotNull;

import java.util.HashMap;
import java.util.List;

import javax.security.auth.callback.Callback;

/**
 * @author KK
 * @description:
 * @date :2021/10/21 11:00
 */
public class CommdityBindRv {
    String name;
    String adress;
    @BindingAdapter(value = {"adapter","pic","title"})
    public static void bindcommodityRv(RecyclerView recyclerView, BaseQuickAdapter adapter,String pic,String title){

        BaseQuickAdapter adapter1 = (BaseQuickAdapter) recyclerView.getAdapter();
        if (adapter1 == null) {
            View headview = LayoutInflater.from(recyclerView.getContext()).inflate(R.layout.item_headrv, null);
            ImageView im = headview.findViewById(R.id.headrv_im);
            TextView tv = headview.findViewById(R.id.headrv_tv);
            LoadImage.loadMatchImg(pic, im);
            tv.setText(title);
            recyclerView.setLayoutManager(new GridLayoutManager(recyclerView.getContext(), 2));
            recyclerView.setAdapter(adapter);
            adapter.addHeaderView(headview);//添加头布局
        }else {
            LinearLayout headerLayout = adapter.getHeaderLayout();
            TextView tv = headerLayout.findViewById(R.id.headrv_tv);
            ImageView im = headerLayout.findViewById(R.id.headrv_im);
            tv.setText(title);
            LoadImage.loadMatchImg(pic,im);
        }

    }

    @BindingAdapter(value = "adapter")
    public static void bindShoppingRv(RecyclerView recyclerView,BaseQuickAdapter adapter){
        recyclerView.setLayoutManager(new LinearLayoutManager(recyclerView.getContext()));
        recyclerView.setAdapter(adapter);

    }


    //订单列表
    @BindingAdapter(value = "OrderListadapter")
    public static void bindOrderList(RecyclerView recyclerView,BaseQuickAdapter adapter){
        recyclerView.setLayoutManager(new LinearLayoutManager(recyclerView.getContext()));
        View foot = LayoutInflater.from(recyclerView.getContext()).inflate(R.layout.item_orderlist_foot, null);

        adapter.addFooterView(foot);
        recyclerView.setAdapter(adapter);
    }



    //地址列表
    @BindingAdapter(value = "Adressadpter")
    public static void bindAdressList(RecyclerView recyclerView,BaseQuickAdapter adapter){
        recyclerView.setLayoutManager(new LinearLayoutManager(recyclerView.getContext()));
        recyclerView.setAdapter(adapter);

    }



}
